//ӦΪJSONAjax
Request.JSON = new Class({

 //̳Request
 Extends: Request,

 options: {
  //ǷǿƷصJSONΪϸʽ
  secure: true
 },

 //Ǹ๹캯
 initialize: function(options){
  //øͬ
  arguments.callee.parent(options);
  //HTTPͷϢ
  this.headers.extend({'Accept': 'application/json', 'X-Request': 'JSON'});
 },

 //ɹ,Requestͬ
 success: function(text){
  //ӽJSONӦ
  this.response.json = JSON.decode(text, this.options.secure);
  //ø෽,ɹ¼
  this.onSuccess(this.response.json, text);
 }

});

 
/*
Լչ,ӦΪXMLAjax
ҪΪصxml󸽼֧XPathselectNodesselectSingleNode
ΪIEѾ֧,Ҫ֧XPath
document.evaluate÷ɲοַ:
http://developer.mozilla.org/en/docs/DOM:document.evaluate
http://wiki.mozcn.org/index.php/Firefox:Dive_Into_Greasemonkey/4.6._Doing_something_for_every_element_with_a_certain_attribute
*/
Request.XML = new Class({

 //̳Request
 Extends: Request,

 //ɹ,Requestͬ
 success: function(text, xml){
  //ΪIEѾ֧,Ҫ֧XPath
  if(Browser.Features.xpath) {
   //չʵselectNodes
   xml.selectNodes = function(xpath){
    var nodes = [], node;
    //
    var result = this.evaluate(xpath, this, this.createNSResolver(this.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;
    if (result) while(node = result.iterateNext()) nodes.push(node);
    return nodes;
   }; 
   //չʵselectSingleNode
   xml.selectSingleNode = function(xpath){
    var result = this.evaluate(xpath, this, this.createNSResolver(this.documentElement), 9, null);
    return (result && result.singleNodeValue) ? result.singleNodeValue : [];
   };
  }
  //ø෽,ɹ¼
  this.onSuccess(xml, text);
 }
});

